//
// callbacks.cc
//

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 * 
 */

#include <X11/keysym.h>
#include "x-osk.h"


bool  XOSK::on_window_kb_button_release_event(GdkEventButton* event)
{
    m_moving = false;
    return false;
}

bool  XOSK::on_window_kb_motion_notify_event(GdkEventMotion* event)
{
    if(!m_moving)
    {
        m_initial_drag_x = event->x;
        m_initial_drag_y = event->y;
    }
    mp_window_kb->move(event->x_root - m_initial_drag_x, event->y_root - m_initial_drag_y);
    m_moving = true;
    return false;
}


void  XOSK::on_button_a_clicked()
{
    keysym_send(XK_a);
}
void  XOSK::on_button_b_clicked()
{
    keysym_send(XK_b);
}
void  XOSK::on_button_c_clicked()
{
    keysym_send(XK_c);
}
void  XOSK::on_button_d_clicked()
{
    keysym_send(XK_d);
}
void  XOSK::on_button_e_clicked()
{
    keysym_send(XK_e);
}
void  XOSK::on_button_f_clicked()
{
    keysym_send(XK_f);
}
void  XOSK::on_button_g_clicked()
{
    keysym_send(XK_g);
}
void  XOSK::on_button_h_clicked()
{
    keysym_send(XK_h);
}
void  XOSK::on_button_i_clicked()
{
    keysym_send(XK_i);
}
void  XOSK::on_button_j_clicked()
{
    keysym_send(XK_j);
}
void  XOSK::on_button_k_clicked()
{
    keysym_send(XK_k);
}
void  XOSK::on_button_l_clicked()
{
    keysym_send(XK_l);
}
void  XOSK::on_button_m_clicked()
{
    keysym_send(XK_m);
}
void  XOSK::on_button_n_clicked()
{
    keysym_send(XK_n);
}
void  XOSK::on_button_o_clicked()
{
    keysym_send(XK_o);
}
void  XOSK::on_button_p_clicked()
{
    keysym_send(XK_p);
}
void  XOSK::on_button_q_clicked()
{
    keysym_send(XK_q);
}
void  XOSK::on_button_r_clicked()
{
    keysym_send(XK_r);
}
void  XOSK::on_button_s_clicked()
{
    keysym_send(XK_s);
}
void  XOSK::on_button_t_clicked()
{
    keysym_send(XK_t);
}
void  XOSK::on_button_u_clicked()
{
    keysym_send(XK_u);
}
void  XOSK::on_button_v_clicked()
{
    keysym_send(XK_v);
}
void  XOSK::on_button_w_clicked()
{
    keysym_send(XK_w);
}
void  XOSK::on_button_x_clicked()
{
    keysym_send(XK_x);
}
void  XOSK::on_button_y_clicked()
{
    keysym_send(XK_y);
}
void  XOSK::on_button_z_clicked()
{
    keysym_send(XK_z);
}
void  XOSK::on_button_0_clicked()
{
    keysym_send(XK_0);
}
void  XOSK::on_button_1_clicked()
{
    keysym_send(XK_1);
}
void  XOSK::on_button_2_clicked()
{
    keysym_send(XK_2);
}
void  XOSK::on_button_3_clicked()
{
    keysym_send(XK_3);
}
void  XOSK::on_button_4_clicked()
{
    keysym_send(XK_4);
}
void  XOSK::on_button_5_clicked()
{
    keysym_send(XK_5);
}
void  XOSK::on_button_6_clicked()
{
    keysym_send(XK_6);
}
void  XOSK::on_button_7_clicked()
{
    keysym_send(XK_7);
}
void  XOSK::on_button_8_clicked()
{
    keysym_send(XK_8);
}
void  XOSK::on_button_9_clicked()
{
    keysym_send(XK_9);
}
void  XOSK::on_button_grave_clicked()
{
    keysym_send(XK_grave);
}
void  XOSK::on_button_minus_clicked()
{
    keysym_send(XK_minus);
}
void  XOSK::on_button_equal_clicked()
{
    keysym_send(XK_equal);
}
void  XOSK::on_button_bracketleft_clicked()
{
    keysym_send(XK_bracketleft);
}
void  XOSK::on_button_bracketright_clicked()
{
    keysym_send(XK_bracketright);
}
void  XOSK::on_button_backslash_clicked()
{
    keysym_send(XK_backslash);
}
void  XOSK::on_button_semicolon_clicked()
{
    keysym_send(XK_semicolon);
}
void  XOSK::on_button_apostrophe_clicked()
{
    keysym_send(XK_apostrophe);
}
void  XOSK::on_button_comma_clicked()
{
    keysym_send(XK_comma);
}
void  XOSK::on_button_period_clicked()
{
    keysym_send(XK_period);
}
void  XOSK::on_button_slash_clicked()
{
    keysym_send(XK_slash);
}
void  XOSK::on_button_tab_clicked()
{
    keysym_send(XK_Tab);
}
void  XOSK::on_button_backspace_clicked()
{
    keysym_send(XK_BackSpace);
}
void  XOSK::on_button_delete_clicked()
{
    keysym_send(XK_Delete);
}
void  XOSK::on_button_return_clicked()
{
    keysym_send(XK_Return);
}
void  XOSK::on_button_home_clicked()
{
    keysym_send(XK_Home);
}
void  XOSK::on_button_end_clicked()
{
    keysym_send(XK_End);
}
void  XOSK::on_button_space_clicked()
{
    keysym_send(XK_space);
}
void  XOSK::on_button_left_clicked()
{
    //m_xorg_lib.send_arrow_left_event();
    keysym_send(XK_Left);
}
void  XOSK::on_button_right_clicked()
{
    //m_xorg_lib.send_arrow_right_event();
    keysym_send(XK_Right);
}
void  XOSK::on_button_up_clicked()
{
    //m_xorg_lib.send_arrow_up_event();
    keysym_send(XK_Up);
}
void  XOSK::on_button_down_clicked()
{
    //m_xorg_lib.send_arrow_down_event();
    keysym_send(XK_Down);
}


void  XOSK::on_button_quit_clicked()
{
    config_file_save();
    mp_window_kb->hide();
}

void  XOSK::on_button_showhide_clicked()
{
    if(!mp_box_row_1->get_visible())
    {
        mp_window_kb->move(m_kb_x, m_kb_y);
        mp_box_row_1->show();
        mp_box_row_2->show();
        mp_box_row_3->show();
        mp_box_row_4->show();
        mp_box_row_5_showhide->show();
    }
    else
    {
        mp_window_kb->get_position(m_kb_x, m_kb_y);
        //cout << "kb pos is " << m_kb_x << ", " << m_kb_y << endl;
        m_bsh_x = m_kb_x + m_kb_w - m_bsh_w;
        m_bsh_y = m_kb_y + m_kb_h - m_bsh_h;
        //cout << "bsh pos is " << m_bsh_x << ", " << m_bsh_y << endl;
        mp_box_row_1->hide();
        mp_box_row_2->hide();
        mp_box_row_3->hide();
        mp_box_row_4->hide();
        mp_box_row_5_showhide->hide();
        mp_window_kb->resize(1, 1);
        mp_window_kb->move(m_bsh_x, m_bsh_y);
    }
}


void  XOSK::on_togglebutton_ctrl_toggled()
{
    
}
void  XOSK::on_togglebutton_alt_toggled()
{
    
}
void  XOSK::on_togglebutton_shift_toggled()
{
    update_keyboard_labels();
}
void  XOSK::on_togglebutton_capslock_toggled()
{
    update_keyboard_labels();
}
